package com.zyh.entity;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class PlayWritable implements WritableComparable<PlayWritable> {
    private Integer viewer;
    private Integer length;

    public PlayWritable() {
    }

    public PlayWritable(Integer viewer, Integer length) {
        this.viewer = viewer;
        this.length = length;
    }

    @Override
    public int compareTo(PlayWritable o) {
        if(this.getLength()<o.getLength()){
            return 1;
        }else{
            if(this.length==o.getLength()){
                if(this.getViewer()<o.getViewer()){
                    return 1;
                }else {
                    if(this.getViewer()==o.getViewer()){
                        return 0;
                    }else {
                        return -1;
                    }
                }
            }else {
                return -1;
            }
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(viewer);
        dataOutput.writeInt(length);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.viewer = dataInput.readInt();
        this.length = dataInput.readInt();
    }

    public Integer getViewer() {
        return viewer;
    }

    public void setViewer(Integer viewer) {
        this.viewer = viewer;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }
}
